package com.hexiang.rocketmq.mq.producer;

import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class TraceProducer {

    @Resource
    private RocketMQTemplate rocketMQTemplate;

    public void sendMsg(String msgBody) {
        SendResult sendResult = rocketMQTemplate.syncSend("test_trace_spring_topic", MessageBuilder.withPayload(msgBody).build());
        // 通过sendResult返回消息是否成功送达
        System.out.printf("%s%n", sendResult);
    }

}